package en.ameen.preciousengine;

import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Typeface;

/*!
That class should display the number of frames per second, it was meant to serve 
as a debug class to serve as an indicator of the performance of the game. At the 
time of this writing, I can tell you that this class may not function properly all 
the time; I need to do some investigation myself.
*/
public class FPSCounter {

	//! Interval to update the counter on screen
	private double updateRate;
	
	//! Elapsed time before reaching the update rate
	private double elapsedInterval;
	
	//! How many frames we counted
	private int frameCounter;
	
	//! Text to be shown on screen
	private int frameText;
	
	
    //! FPS Constructor
    /*!
      Initialize the class by zeroing everything.
      \param updateRate context to initialize the scene from

    */
	public FPSCounter(double updateRate) {

		this.updateRate = updateRate;
		this.elapsedInterval = 0;
		this.frameCounter = 0;
		this.frameText = 0;
		
	}
	
    //! Function to update the FPS Count
    /*!
      This will count how many frames we rendering
      \param elapsed elapsed time passed

    */
	public void updateFPS(double elapsed){
		
		elapsedInterval += elapsed;
		frameCounter++;
		
		if (elapsedInterval >= updateRate){
			
			elapsedInterval = 0;
			
			frameText = frameCounter;
			frameCounter = 0;
	
		}

	}
	
    //! Function to render FPS count
    /*!
      This will render the FPS on screen
      \param canvas Canvas to render on
    */
	public void renderFPS(Canvas canvas){
		
		Paint textPaint = new Paint();
		
		textPaint.setColor(Color.BLACK);
		textPaint.setTextSize(20);
		textPaint.setTypeface(Typeface.SERIF);
		
		canvas.drawText("FPS: " + frameText, 50, 50, textPaint);
		
	}
	

}
